package com.wpzf.zxhc.service.impl;

import com.wpzf.zxhc.domain.WpCjTbhcjg2023DTO;
import com.wpzf.zxhc.mapper.WpzfUnitHcTaskMapper;
import com.wpzf.zxhc.service.CommonService;
import com.wpzf.zxhc.service.WpzfUnitHcTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import java.util.Map;

@Service
public class WpzfUnitHcTaskServiceImpl implements WpzfUnitHcTaskService {

    @Autowired
    WpzfUnitHcTaskMapper wpzfUnitHcTaskMapper;

    @Override
    public List<Map<String, Object>> query_unit_w_task(Map<String, Object> parm) {  /*获取未完成任务列表*/
        return wpzfUnitHcTaskMapper.query_unit_w_task(parm);
    }

    @Override
    public Integer query_unit_w_task_count(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_unit_w_task_count(parm);
    }

    @Override
    public List<Map<String, Object>> query_wwc_Provs(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_wwc_Provs(parm);
    }

    @Override
    public List<Map<String, Object>> query_wwc_Citys(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_wwc_Citys(parm);
    }

    @Override
    public List<Map<String, Object>> query_unit_w_task_list(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_unit_w_task_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_unit_wtask_list(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_unit_wtask_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_unit_y_task(Map<String, Object> parm) {  /*获取已完成任务列表*/
        return wpzfUnitHcTaskMapper.query_unit_y_task(parm);
    }

    @Override
    public Integer query_unit_y_task_count(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_unit_y_task_count(parm);
    }

    @Override
    public List<Map<String, Object>> query_ywc_Provs(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_ywc_Provs(parm);
    }

    @Override
    public List<Map<String, Object>> query_ywc_Citys(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_ywc_Citys(parm);
    }

    @Override
    public List<Map<String, Object>> query_unit_y_task_list(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_unit_y_task_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_unit_ytask_list(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_unit_ytask_list(parm);
    }

    @Override
    public int updateSubmit(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.updateSubmit(parm);
    }  /*提交核查结果*/

    @Override
    public int getTBCount(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.getTBCount(parm);
        if (map != null) {
            count = ((Number) map.get("taskcount")).intValue();
        }
        return count;
    }  /*查询当前行政区已核查的图斑数量*/

    @Override
    public List<Map<String, Object>> get_unit_user_y_static(Map<String, Object> parm) {  /*获取当前用户所有已完成的任务*/
        return wpzfUnitHcTaskMapper.get_unit_user_y_static(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_user_w_static(Map<String, Object> parm) {  /*获取当前用户所有未完成的任务*/
        return wpzfUnitHcTaskMapper.get_unit_user_w_static(parm);
    }

    @Override
    public int get_unit_user_w_static_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_user_w_static_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> get_unit_dqr_static(Map<String, Object> parm) {  /*<!--获取当前用户所有待确认任务-->*/
        return wpzfUnitHcTaskMapper.get_unit_dqr_static(parm);
    }

    @Override
    public Integer get_unit_dqr_static_count(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_dqr_static_count(parm);
    }

    @Override
    public List<Map<String, Object>> queryProvs(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.queryProvs(parm);
    }

    @Override
    public List<Map<String, Object>> queryCitys(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.queryCitys(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_dqr_static_list(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_dqr_static_list(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_yqr_static(Map<String, Object> parm) {  /*获取当前用户所有已确认任务*/
        return wpzfUnitHcTaskMapper.get_unit_yqr_static(parm);
    }

    @Override
    public Integer get_unit_yqr_static_count(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_yqr_static_count(parm);
    }

    @Override
    public List<Map<String, Object>> query_yqr_Provs(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_yqr_Provs(parm);
    }

    @Override
    public List<Map<String, Object>> query_yqr_Citys(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.query_yqr_Citys(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_yqr_static_list(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_yqr_static_list(parm);
    }

    @Override
    public int getTbhcjglist(Map<String, Object> parm) {  /*获取当前用户所有未完成的任务*/
        Integer count = 0;
        List<Map<String, Object>> map = wpzfUnitHcTaskMapper.getTbhcjglist(parm);
        if (map != null) {
            count = map.size();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> get_usertask_static(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_usertask_static(parm);
    }

    @Override
    public Integer get_usertask_static_count(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_usertask_static_count(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_pchlist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_pchlist(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_tasklist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_tasklist(parm);
    }

    @Override
    public int get_unit_tasklist_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_tasklist_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> get_unit_prov(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_prov(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_city(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_city(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_wfp_tasklist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_wfp_tasklist(parm);
    }

    @Override
    public int get_unit_wfp_tasklist_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_wfp_tasklist_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public int add_pf_user(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.add_pf_user(parm);
    }

    @Override
    public int update_pf_user(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.update_pf_user(parm);
    }

    @Override
    public List<Map<String, Object>> get_dwhcrw_pf(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_dwhcrw_pf(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_static_user(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_static_user(parm);
    }

    @Override
    public int get_unit_static_user_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_static_user_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> get_unit_static(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_static(parm);
    }

    @Override
    public int get_unit_static_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_static_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public int add_unit_user(Map<String, Object> map) {
        return wpzfUnitHcTaskMapper.add_unit_user(map);
    }

    @Override
    public List<Map<String, Object>> get_unit_tbbhlist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_tbbhlist(parm);
    }

    @Override
    public Integer get_unit_tbbhlist_count(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_tbbhlist_count(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_not_confirmtbbhlist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_not_confirmtbbhlist(parm);
    }

    @Override
    public int get_unit_not_confirmtbbhlist_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_not_confirmtbbhlist_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> get_unit_confirmtbbhlist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_confirmtbbhlist(parm);
    }

    @Override
    public int get_unit_confirmtbbhlist_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_confirmtbbhlist_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> get_unit_yfp_tasklist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_yfp_tasklist(parm);
    }

    @Override
    public List<Map<String, Object>> get_unit_yfp_wz_tasklist(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.get_unit_yfp_wz_tasklist(parm);
    }

    @Override
    public int get_unit_yfp_wz_tasklist_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_yfp_wz_tasklist_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> getJlhcjgqrSheng(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.getJlhcjgqrSheng(parm);
    }

    @Override
    public List<Map<String, Object>> getJlhcjgqrXian(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.getJlhcjgqrXian(parm);
    }

    @Override
    public List<Map<String, Object>> getJlhcjgqrLeftList(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.getJlhcjgqrLeftList(parm);
    }

    @Autowired
    CommonService commonService;

    @Override
    public Integer jlhcjgqrSubmit(Map<String, Object> parm) {
        Integer rest = 0;
        List<Map<String, Object>> selectList = (List<Map<String, Object>>) parm.get("selectList");
        if (selectList != null) {
            for (Map<String, Object> map : selectList) {
                String jl_jljgqr = map.get("jl_jljgqr") + "";
                map.put("username", parm.get("username"));
                map.put("realname", parm.get("realname"));
                map.put("dwmc", parm.get("dwmc"));
                map.put("adddate", new SimpleDateFormat("yyyy-MM-dd HH:MM:ss").format((new Date()).getTime()));
                Map<String, Object> m = wpzfUnitHcTaskMapper.getShByTbbh(map);
                map.put("dwmc", parm.get("dwmc"));

                if ("不同意".equals(jl_jljgqr)) {
                    map.put("ywhj", "0");
                    try {
                        Map<String, Object> tbhcjgsm = commonService.getHcjgsmBytbbh(map);
                        if (tbhcjgsm != null) {
                            map.put("hcjgsm", tbhcjgsm.get("hcjgsm").toString());
                            map.put("jcmj", tbhcjgsm.get("txjcmj")!=null?tbhcjgsm.get("txjcmj"):0);
                            map.put("dlrdgdmj", tbhcjgsm.get("dlrdgdmj")!=null?tbhcjgsm.get("dlrdgdmj"):0);
                            map.put("tb_gdmj", tbhcjgsm.get("tb_gdmj")!=null?tbhcjgsm.get("tb_gdmj"):0);
                            map.put("tb_jbntmj", tbhcjgsm.get("tb_qzjbntmj")!=null?tbhcjgsm.get("tb_qzjbntmj"):0);
                            map.put("zphlxjc", tbhcjgsm.get("zphlxjc")!=null?tbhcjgsm.get("zphlxjc"):null);
                            map.put("yxzpdl", tbhcjgsm.get("yxzpdl")!=null?tbhcjgsm.get("yxzpdl"):null);
                        }
                    } catch (Exception ex) {

                    }
                    if (m != null) {
                        wpzfUnitHcTaskMapper.updateSh(map);
                    } else {
                        wpzfUnitHcTaskMapper.saveSh(map);
                    }
                } else if ("同意".equals(jl_jljgqr)) {
                    map.put("ywhj", "1");
                    WpCjTbhcjg2023DTO tbhcjg = wpzfUnitHcTaskMapper.getTbhcjg(map);
                    map.put("username", tbhcjg.getUsername());
                    map.put("realname", tbhcjg.getShr());
                    String dwmc = wpzfUnitHcTaskMapper.getUserDepartment(map);
                    map.put("dwmc", dwmc);
                    try {
                        Map<String, Object> tbhcjgsm = commonService.getHcjgsmBytbbh(map);
                        if (tbhcjgsm != null) {
                            map.put("hcjgsm", tbhcjgsm.get("hcjgsm").toString());
                            map.put("jcmj", tbhcjgsm.get("txjcmj")!=null?tbhcjgsm.get("txjcmj"):0);
                            map.put("dlrdgdmj", tbhcjgsm.get("dlrdgdmj")!=null?tbhcjgsm.get("dlrdgdmj"):0);
                            map.put("tb_gdmj", tbhcjgsm.get("tb_gdmj")!=null?tbhcjgsm.get("tb_gdmj"):0);
                            map.put("tb_jbntmj", tbhcjgsm.get("tb_qzjbntmj")!=null?tbhcjgsm.get("tb_qzjbntmj"):0);
                            map.put("zphlxjc", tbhcjgsm.get("zphlxjc")!=null?tbhcjgsm.get("zphlxjc"):null);
                            map.put("yxzpdl", tbhcjgsm.get("yxzpdl")!=null?tbhcjgsm.get("yxzpdl"):null);
                        }
                    } catch (Exception ex) {

                    }
                    if (m != null) {
                        wpzfUnitHcTaskMapper.updateSh(map);
                    } else {
                        wpzfUnitHcTaskMapper.saveSh(map);
                    }
                }
                map.put("sftj_submitdate", new SimpleDateFormat("yyyy-MM-dd HH:MM:ss").format((new Date()).getTime()));
                rest += wpzfUnitHcTaskMapper.jlhcjgqrSubmit(map);
            }
        }
        return rest;
    }

    @Override
    public List<Map<String, Object>> dwUnitLeaderLeftList(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.dwUnitLeaderLeftList(parm);
    }

    @Override
    public List<Map<String, Object>> getWjXxTqjgByWjmc(Map<String, Object> parm) {
        return wpzfUnitHcTaskMapper.getWjXxTqjgByWjmc(parm);
    }

    @Override
    public int get_unit_user_y_static_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfUnitHcTaskMapper.get_unit_user_y_static_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }


}
